//
//  IdeaDataWebViewController.m
//  LiangYa_BObject
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 YuHao. All rights reserved.
//

#import "IdeaDataWebViewController.h"

@interface IdeaDataWebViewController ()<UIWebViewDelegate>
@property (nonatomic, strong) NSString *itemUrl;
@property (nonatomic, strong) UIButton *backB;
@property (nonatomic, strong) MBProgressHUD *HUD;
@end

@implementation IdeaDataWebViewController

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
//    [HUD removeFromSuperview];
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [AFRequdstAndLoad dataURLStr:self.webUrl datahand:^(id object) {

        NSDictionary *dic1 = [object objectForKey:@"data"];
        NSDictionary *dic2 = [dic1 objectForKey:@"itemInfoModel"];
        self.itemUrl = [dic2 objectForKey:@"itemUrl"];
        
        
        UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, Screenheight - 0)];
        webView.delegate = self;
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.itemUrl]];
        [self.view addSubview:webView];
        [webView loadRequest:request];
        for (id subview in webView.subviews)
            if ([[subview class] isSubclassOfClass: [UIScrollView class]])
                ((UIScrollView *)subview).bounces = NO;
        
        self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];

        _HUD.labelText = @"数据加载中...";

        // 返回按钮
        self.backB = [UIButton buttonWithType:UIButtonTypeSystem];
        _backB.backgroundColor = [UIColor colorWithRed:1.000 green:0.000 blue:0.139 alpha:1.000];
        _backB.frame = CGRectMake(20, 40, 40, 40);
        _backB.layer.cornerRadius = 20;
        UIImage *backI = [[UIImage imageNamed:@"picture1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [_backB setImage:backI forState:UIControlStateNormal];
        [_backB setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
        [_backB addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
        [webView addSubview:_backB];
    }];
   

}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [_HUD removeFromSuperview];
}

- (void)backAction:(UIButton *)btn
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
